package dolf.window;
import javax.swing.*;

import javax.swing.border.*;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import dolf.game.*;


public class PlayerDisplay extends JPanel {
	private static final long serialVersionUID = 1L;
	private JScrollPane scrollPane;
	
	private static PlayerDisplay instance = new PlayerDisplay();

	public static PlayerDisplay getInstance() {
		return instance;
	}
	private PlayerDisplay() {}
	
	public void draw() {
		this.removeAll();
		final JPanel pane = new JPanel();
		//pane.setLayout(new BoxLayout(pane,BoxLayout.PAGE_AXIS));
		pane.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();

		int i = 0;
		for (final Player pl : Game.getInstance().getPlayerList()) {
			gbc.fill = GridBagConstraints.NONE;
			gbc.anchor = GridBagConstraints.NORTHWEST;
			gbc.gridx = 0;
			gbc.gridy = i;
			
			pane.add(pl.getPlayerPane(), gbc);

			JLabel spacing = new JLabel();
			spacing.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
			
			i++;
			gbc.fill = GridBagConstraints.NONE;
			gbc.anchor = GridBagConstraints.NORTHWEST;
			gbc.gridx = 0;
			gbc.gridy = i;
			pane.add(spacing, gbc);
			i++;
		}
		JPanel pane2 = new JPanel(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
		pane2.add(pane);
		scrollPane = new JScrollPane(pane2);
		scrollPane.getVerticalScrollBar().setUnitIncrement(10);
		scrollPane.setPreferredSize(new java.awt.Dimension(130,400));
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane.setViewportBorder(new EmptyBorder(0,0,0,0));
		scrollPane.setBorder(new EmptyBorder(0,0,0,0));
		this.add(scrollPane);
						
		if (! (Level.getInstance().getAktualPlayer() == null))
			scrollPane.getViewport().setViewPosition(Level.getInstance().getAktualPlayer().getPlayerPane().getBounds().getLocation());
		MainWindow.getInstance().actualize();
		
	}
	
}

